package com.nuo.common.utils;


import lombok.extern.slf4j.Slf4j;

import java.lang.reflect.Field;
import java.util.Arrays;

/**
 * @description: TODO obj 工具类
 * @author nuo
 * @date 2022/11/25 12:52
 * @version 1.0
 */
@Slf4j
public class ObjectUtil {

    /**
     * @description: 判断实体类是否为空
     * @param t
     * @return boolean
     * @date: 2022/11/25 13:06
     */
    public static <T> boolean isNotNullEntity(T t) {
        Class<?> clazz = t.getClass();
        Field[] fields = clazz.getDeclaredFields();
        for (Field field : fields) {
            field.setAccessible(true);
            try {
                if (!"serialVersionUID".equals(field.getName()) && field.get(t) != null) {
                    log.info("k: " + field.getName() + ", v: " + field.get(t).toString());
                    return true;
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return false;
    }


    /**
     * @description: 判断实体类是否为空
     * @param t
     * @return boolean
     * @date: 2022/11/25 13:06
     */
    public static <T> boolean getNullContent(T t) {
        Class<?> clazz = t.getClass();
        Field[] fields = clazz.getDeclaredFields();
        for (Field field : fields) {
            field.setAccessible(true);
            try {
                if (!"serialVersionUID".equals(field.getName()) && field.get(t) != null) {
                    log.info("k: " + field.getName() + ", v: " + field.get(t).toString());
                    return true;
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return false;
    }

}
